package com.sgcc.epri.dcloud.controller;

import com.sgcc.epri.dcloud.pojo.ManagementUnit;
import com.sgcc.epri.dcloud.pojo.Result;
import com.sgcc.epri.dcloud.service.ManagementUnitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/managementUnit")
@Api(description = "治理单位")
public class ManagementUnitController {

    @Autowired
    private ManagementUnitService managementUnitService;

    @GetMapping("/select")
    @ApiOperation("治理单位查询")
    public Result select(@RequestParam(value = "treeId",required = true) @ApiParam(value = "树形结构id", name = "treeId", required = true) String treeId){
        return managementUnitService.select(treeId);
    }

    @PostMapping("/update")
    @ApiOperation("目前只允许修改：hidden_flag字段，0隐藏、1不隐藏")
    public Result update(@RequestBody ManagementUnit managementUnit){
        return managementUnitService.update(managementUnit);
    }

    @PostMapping("/insert")
    @ApiOperation("治理单位新增")
    public Result insert(@RequestBody ManagementUnit managementUnit){
        return managementUnitService.insert(managementUnit);
    }

    @DeleteMapping("/delete")
    @ApiOperation("治理单位删除")
    public Result delete(@RequestParam(required = true) String id){
        return managementUnitService.delete(id);
    }

    @GetMapping("/oneClickImport")
    @ApiOperation("一键导入常规数据源或沿用配置，此前有数据则提示【这将删除现有数据并替换成新数据，确定要这样做吗？】")
    public Result oneClickImport(@RequestParam(value = "treeId",required = true) @ApiParam(value = "树形结构id", name = "treeId", required = true) String treeId,
                                 @RequestParam(value = "type",required = true) @ApiParam(value = "常规数据源(101) or 沿用配置(102)", name = "type", required = true) String type,
                                 @RequestParam(value = "referToTreeId",required = false) @ApiParam(value = "参考那个节点的数据源?", name = "referToTreeId", required = false) String referToTreeId){
        return managementUnitService.oneClickImport(treeId, type, referToTreeId);
    }


    @GetMapping("/upOrDown")
    @ApiOperation("上移或下移")
    public Result upOrDown(@RequestParam(value = "hostId",required = true) @ApiParam(value = "主id 初始位置", name = "hostId", required = true) String hostId,
                           @RequestParam(value = "rmId",required = true) @ApiParam(value = "次id 目标位置", name = "rmId", required = true) String rmId){
        return managementUnitService.upOrDown(hostId, rmId);
    }

    @GetMapping("/queryManagementUnit")
    @ApiOperation("获取治理单位")
    public Result queryManagementUnit(){
        return managementUnitService.queryManagementUnit();
    }

}
